const express = require('express')

const router = express.Router()


const expressJoi = require('@escook/express-joi')

// 导入验证规则
const userinfo_handle = require('../router_handle/userinfo')
const { update_userSchema, update_passwordSchema, update_avater } = require('../schema/user')

//导入multer和path,解析form-data的数据，就是上传文件和图片有关

// 导入解析formdata格式表单数据包
const multer = require('multer')
//导入处理路径的核心模块
const path = require('path')
const db = require('../db')

var storage = multer.diskStorage({
    destination: function (req, file, cb) {
        cb(null, path.join(__dirname, '../upload'))
    },
    filename: function (req, file, cb) {
        cb(null, file.originalname)
    }
})

var upload = multer({ storage: storage })


//获取本人用户信息
router.get('/userinfo', userinfo_handle.get_userInfo)

// 更新用户信息
router.post('/userinfo', expressJoi(update_userSchema), userinfo_handle.update_userInfo)


//修改用户密码
router.post('/updatePwd', expressJoi(update_passwordSchema), userinfo_handle.update_password)

//修改头像
router.post('/updateAvater', expressJoi(update_avater), userinfo_handle.update_avater)

//查询公告
router.get('/getNotice', userinfo_handle.get_notice)

//获取已选课题的信息
router.get('/getTopic', userinfo_handle.get_topic)

//获取所有课题信息
router.get('/getAllTopic', userinfo_handle.get_allTopic)

//查看课题信息
router.get('/topic', userinfo_handle.get_topicinfo)

//发送文件,使用upload.single中间件,里面的名称最好和你要上传的数据库的名称1一致
router.post('/add', upload.single('file'), userinfo_handle.add_report)


//获取教师的指导记录
router.get('/direct', userinfo_handle.get_direct)

//展示教师的指导记录内容
router.get('/show_direct', userinfo_handle.show_direct)

//获取教师的留言信息
router.get('/getmessage', userinfo_handle.get_message)


//学生发送留言
router.post('/postmessage', userinfo_handle.post_message)

//获取教师信息
router.get('/teacherinfo', userinfo_handle.get_teacherinfo)


//选择课题按钮
router.post('/choosebtn', userinfo_handle.send_topic)


//获取个人任务书
router.get('/choose_task', userinfo_handle.choose_task)


//获取开题报告信息
router.get('/get_report', userinfo_handle.get_report)

//获取个人的论文信息
router.get('/get_paper', userinfo_handle.get_paper)

//删除个人的论文
router.post('/dele_paper', userinfo_handle.dele_paper)

//上传个人的论文
router.post('/add_paper', upload.single('file'), userinfo_handle.add_paper)

//查看个人论文分数
router.get('/get_score', userinfo_handle.get_score)

//查看个人答辩小组信息
router.get('/get_defence', userinfo_handle.get_defence)

//添加文件类型
// router.post('/insertType', userinfo_handle.insertType)

module.exports = router